using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using  server.status_db;
[Authorize]
public class XnqkController : ODataController
{
    private status_oneContext _db;
    public XnqkController(status_oneContext context)
    {
        _db = context;

    }
    private bool MCExists(Guid key)
    {
        return _db.PG_B_XNZRJBQK.Any(p => p.ID == key);
    }
    [HttpPut]
    public async Task<IActionResult> Put([FromODataUri] Guid key, [FromBody]PG_B_XNZRJBQK update)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        if (key != update.ID)
        {
            return BadRequest();
        }
        _db.Entry(update).State = EntityState.Modified;
        try
        {
            await _db.SaveChangesAsync();
        }
        catch (DbUpdateConcurrencyException)
        {
            if (!MCExists(key))
            {
                return NotFound();
            }
            else
            {
                throw;
            }
        }
        return Updated(update);
    }
    public async Task<IActionResult> Delete([FromODataUri] Guid key)
    {
        var mc = await _db.PG_B_XNZRJBQK.FindAsync(key);
        if (mc == null)
        {
            return NotFound();
        }
        _db.PG_B_XNZRJBQK.Remove(mc);
        await _db.SaveChangesAsync();
        return NoContent();
    }
    [HttpPost]
    public async Task<IActionResult> Post([FromBody] PG_B_XNZRJBQK model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        _db.PG_B_XNZRJBQK.Add(model);
        await _db.SaveChangesAsync();

        return Created(model);
    }
    [EnableQuery]
    public IActionResult Get()
    {
        return Ok(_db.PG_B_XNZRJBQK);
    }
    //
}